// pages/personal/record/record.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        scrollTop: 0,
        scrollHeight: 0,
        list: [],
        hidden: true,
        page: 1,
        pageSize: 6,
        total: 23,
        imgUri: 'http://tsw-qqc.oss-cn-hangzhou.aliyuncs.com'
    },
    // 获取记录
    getData(updata) {
        let data = []
        let index = this.data.pageSize
        let page = this.data.page
        let _this = this
        if (wx.getStorageSync('userId') == ''){
          wx.showModal({
            title: '提示',
            content: '请返回个人中心获取头像昵称！',
            showCancel: false,
            success:function(e){
              wx.navigateBack({})
            }
          })
          return
        }
        wx.request({
            url: getApp().globalData.api + '/a/wxinterface/personDonate', //
            data: {
              userId: wx.getStorageSync('userId'),//getApp().globalData.userId,
              pageNo: page,
              pageSize: index
            },
            header: {
                'content-type': 'application/json' // 默认值
            },
            success: function (res) {
                let _data = res.data
                let _total = 0
                for (var i = 0; i < _data.obj.length; i++) {
                    data.push({
                        time: _data.obj[i].payTime,
                        title: _data.obj[i].eventName,
                        donation: _data.obj[i].amount,
                        imgUrl: _data.obj[i].eventPicUrl
                    })
                    _total = _data.obj[0].total
                }

                _this.setData({
                    list: _this.data.list.concat(data),
                    total: _total
                })
                if (_this.data.list.length >= _this.data.total) {
                    _this.setData({
                        hidden: false
                    })
                }
            }
        })
    },
    // 上拉加载
    lower() {
        let currentPage = this.data.page
        if (currentPage * this.data.pageSize >= this.data.total) {
            return
        }
        currentPage ++
        this.setData({
            page: currentPage
        });
        this.getData(true)
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        var that = this;
        wx.getSystemInfo({
            success:function(res) {
                that.setData({
                    scrollHeight:res.windowHeight
                });
            }
        });
        this.getData()
    },
    onPullDownRefresh: function () {
        this.setData({
            page: 1,
            scrollTop: 0,
            list: []
        });
        this.getData()
        wx.stopPullDownRefresh();
    }
})